<template>
    <view class="container" :style="{paddingBottom:courseDatail.userBuyed==0?'100rpx':''}">
        <!-- 美丽日志 -->
        <view class="log_block" v-if="wuliuData.length!=0">
            <view class="log_item" v-for="(itemData,index) in wuliuData" :key="index" @click="callTelnoFun(itemData)">
                <!-- <view class="log_item_left">
                    <text class="log_item_date">{{itemData.time}}</text>
                    <text class="log_item_month" :style="'color:'+defaultColor">{{itemData.month}}</text>
                </view> -->
                <view class="log_item_rigth" :style="'padding-top:'+(index==0?'':'30rpx')">
                    <view class="line" :style="'border-left:2rpx solid '+defaultColor+'55'"></view>
                    <view class="log_item_title">
                        <view class="log_item_title_left">
                            <view :class="['log_item_title_dot',index==0?'':'log_item_title_dot_one']" :style="'border:8rpx solid '+(index==0?secondColor:'#ccc')+';background:'+(index==0?defaultColor:'#ccc')"></view>
                            <rich-text class="log_item_title_text" :style="'color:'+(index==0?defaultColor:'#999')" :nodes='itemData.context'></rich-text>
                        </view>
                        <!-- <view class="log_item_title_right">
                            <image class="share_icon" src="https://image1.sansancloud.com/xianhua/2020_2/27/18/34/10_820.jpg?x-oss-process=style/preview_120"></image>
                        </view> -->
                    </view>
                    <view class="log_item_info">
                        <!-- <view class="log_item_img_list" v-if="itemData.commitJson.moreImg.value&&itemData.commitJson.moreImg.value.length!=0">
                            <view class="log_item_img_item" v-if="itemData.commitJson.moreImg.value.length>2" v-for="(imgItem,imgIndex) in itemData.commitJson.moreImg.value" :key="imgIndex" @tap="lookBigImage" :data-imageUrl="itemData.commitJson.moreImg.value" :data-index="imgIndex">
                                <image class="img_item" mode="aspectFill" :src="imgItem"></image>
                            </view>
                            <view class="log_item_img_item" style="width: 280rpx;height: 280rpx;" v-if="itemData.commitJson.moreImg.value.length==2" v-for="(imgItem,imgIndex) in itemData.commitJson.moreImg.value" :key="imgIndex" :data-imageUrl="itemData.commitJson.moreImg.value" :data-index="imgIndex" @tap="lookBigImage">
                                <image class="img_item" mode="aspectFill" :src="imgItem"></image>
                            </view>
                            <view class="log_item_img_item" style="height: 100%;" v-if="itemData.commitJson.moreImg.value.length==1" v-for="(imgItem,imgIndex) in itemData.commitJson.moreImg.value" :key="imgIndex" :data-imageUrl="itemData.commitJson.moreImg.value" :data-index="imgIndex" @tap="lookBigImage">
                                <image class="img_item" mode="widthFix" :src="imgItem"></image>
                            </view>
                        </view> -->
                        <view class="log_item_info_bottom" :style="'border-bottom:1rpx solid '+defaultColor+'55'">
                            <view class="commit_time" :style="'color:'+(index==0?defaultColor:'#999')">{{itemData.time}}</view>
                            <view class="log_item_info_fun">
                            </view>
                        </view>
                    </view>
                </view>
            </view>
        </view>
        <view class="no_wuliu_data" v-else>
          <image mode="widthFix" src='https://image1.sansancloud.com/xianhua/2019_12/16/15/54/55_950.jpg?x-oss-process=style/preview_120'></image>
          <text>没有相关物流信息~</text>
        </view>
    </view>
</template>

<script>
import { socketFun } from "../../wxcomponents/public/json2Form";
import uniSteps from "@dcloudio/uni-ui/lib/uni-steps/uni-steps.vue"
export default {
  components: {uniSteps},
  data() {
    return {
      wuliuData:null,
      params:{},
      setting:null,
      defaultColor:'',
      secondColor:'',
    };
  },
  props: {},

  /*onload*/
  onLoad: function (options) {
    let that=this;
    console.warn("======onLoad:options======", options, getApp().globalData.setting);
    that.params=options;
    that.getWuliuData(options);
  },
  onReady: function () {
    
  },
  onShow: function () {
    let that=this;
	that.setData({
        setting:getApp().globalData.setting,
        defaultColor:getApp().globalData.setting.platformSetting.defaultColor,
        secondColor:getApp().globalData.setting.platformSetting.secondColor,
       })
  },
  /* 分享 app.js862行*/
  onShareAppMessage: function () {
    console.log(getApp().globalData.miniIndexPage);
    return getApp().globalData.shareForFx2(getApp().globalData.miniIndexPage);
  },
  onPullDownRefresh: function () {
    let that = this; // 下拉刷新的时候首先判断存不存在tab
    console.log("下拉");
    that.getWuliuData(that.params);
    wx.stopPullDownRefresh();
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    console.log('===onReachBottom====');
    let that = this
    // if (that.listPage.totalSize > that.listPage.page * that.listPage.pageSize) {
    //   that.listPage.page++
    //   that.getData(that.listPage,'upload');
    // }else{
    //     wx.showToast({
    //       title: "到底了~",
    //       image: '/wxcomponents/images/icons/tip.png',
    //       duration: 1000
    //     });
    // }
  },
  onPageScroll: function (object) {
      let that=this;
      // that.setData({
      //   scroll: object.scrollTop
      // })
  },
  methods: {
    callTelnoFun:function(itemData){
        console.log("==callTelnoFun===",itemData);
        let that=this;
        if(itemData.telnoArr&&itemData.telnoArr.length!=0){
            wx.showActionSheet({
              itemList: itemData.telnoArr,
              success: function (res) {
                console.log(res);
                getApp().globalData.calling(itemData.telnoArr[res.tapIndex])
              }
            })
        }
    },
    loginStateFun:function(courseId){
        let that=this;
        if (getApp().globalData.loginUser && getApp().globalData.loginUser.platformUser.id) {
          that.confirmReserve(courseId)
        } else {
          wx.showModal({
            title: '提示',
            content: '您还未登录，请先登入~',
            success: function (res) {
              if (res.confirm) {
                  getApp().globalData.addLoginListener(that);
                  let url='login.html?url=';
                  let backUrl='course_detail.html?instanceId='+that.params.instanceId;
                  url+= encodeURIComponent(backUrl)
                  getApp().globalData.linkEvent(url)
              } else if (res.cancel) {}
            }
          });
        }
    },
    /* 获取数据 */
    getWuliuData: function (params) {
      var that = this
      var customIndex = getApp().globalData.AddClientUrl("/wx_get_order_kuaidi.html", params)
      getApp().globalData.showToastLoading('loading', true)
      wx.request({
        url: customIndex.url,
        header: getApp().globalData.header,
        success: function (res) {
          wx.hideLoading()
          console.log(res.data)
          let data=res.data.relateObj?res.data.relateObj.data:null;
          if (!data) {
            that.setData({ wuliuData: [] })
          } else {
              for(let i=0;i<data.length;i++){
                  let re=/((((13[0-9])|(15[^4])|(18[0,1,2,3,5-9])|(17[0-8])|(147))\d{8})|((\(\d{3,4}\)|\d{3,4}-|\s)?\d{7,14}))?/g;
                  // var re = /\d{11}/g;
                  let arr =(data[i].context.match(re)).filter(function (s) {
                       return s && s.trim();
                    });;
                  console.log("==arr===",arr)
                  if(arr){
                      data[i].telnoArr=arr;
                      for(var j = 0; j < arr.length; j++){
                        console.log("arrj",arr[j]);
                        data[i].context=data[i].context.replace(new RegExp(arr[j],'g'),'<span style="color:red"> '+arr[j]+' </span>')
                      }
                  }
                  // data[i].context=data[i].context+'<span style="color:red">18950462515</span>'
              }
              console.log("==data===",data)
            that.setData({ wuliuData: data })
          }
          wx.hideLoading()
        },
        fail: function (res) {
          console.log("fail")
          wx.hideLoading()
          getApp().globalData.loadFail()
        }
      })
    },
    /* 组件事件集合 */
    tolinkUrl: function (e) {
      console.warn("=======e=======", e);
      let linkUrl = e.currentTarget?e.currentTarget.dataset.url:e;
      getApp().globalData.linkEvent(linkUrl);
    },
    setData: function (obj) {
      let that = this;
      let keys = [];
      let val, data;
      Object.keys(obj).forEach(function (key) {
        keys = key.split('.');
        val = obj[key];
        data = that.$data;
        keys.forEach(function (key2, index) {
          if (index + 1 == keys.length) {
            that.$set(data, key2, val);
          } else {
            if (!data[key2]) {
              that.$set(data, key2, {});
            }
          }

          data = data[key2];
        });
      });
    }
  }
};
</script>
<style>
@import "./index.css";
</style>